package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ForumListBean;
import cn.bocweb.spinning.util.DeviceUtil;
import cn.bocweb.spinning.view.common.GlideCircle;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 16/6/28.
 */
public class MainForum1Adapter extends MyAdapter<ForumListBean.DataBean> {


    public MainForum1Adapter(Context context, List<ForumListBean.DataBean> list) {
        super(context, list);
    }

//    @Override
//    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        mContext = parent.getContext();
//        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_forum2, parent, false);
//        return new ViewHolder(view);
//    }
//
//    @Override
//    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        ViewHolder holder1 = (ViewHolder) holder;
//
//        holder1.mTitle.setText(mList.get(position).getTitle());
//        holder1.mContent.setText(mList.get(position).getContent());
//        if (mList.get(position).getPhoto() != null) {
//            Glide
//                    .with(mContext)
//                    .load(mList.get(position).getPhoto().get(0))
//                    .into(holder1.mImg);
//        }
//        holder1.mTime.setText(
//                DeviceUtil.getTimeByTwoTimeStampForPhp(
//                        Long.parseLong(mList.get(position).getTimeline()) * 1000,
//                        System.currentTimeMillis()));
//
//    }

//    @Override
//    public int getItemCount() {
//        return mList.size();
//    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder1;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_main_forum1, parent, false);
            holder1 = new ViewHolder(convertView);
            convertView.setTag(holder1);
        } else {
            holder1 = (ViewHolder) convertView.getTag();
        }
        Glide
                .with(context)
                .load(list.get(position).getUthumb())
                .placeholder(R.mipmap.login_head)
                .transform(new GlideCircle(context))
                .into(holder1.mIcon);
        holder1.mNickName.setText(list.get(position).getNickname());
        holder1.mReply.setText(list.get(position).getCount());
        holder1.mTitle.setText(list.get(position).getTitle());
        holder1.mContent.setText(list.get(position).getContent());
        holder1.mTime.setText(
                DeviceUtil.getTimeByTwoTimeStampForPhp(
                        Long.parseLong(list.get(position).getTimeline()) * 1000,
                        System.currentTimeMillis()));
        holder1.mLvAnswer.setVisibility(View.GONE);
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.icon)
        ImageView mIcon;
        @Bind(R.id.nick_name)
        TextView mNickName;
        @Bind(R.id.time)
        TextView mTime;
        @Bind(R.id.reply)
        TextView mReply;
        @Bind(R.id.iv_answer)
        ImageView mIvAnswer;
        @Bind(R.id.tv_answer)
        TextView mTvAnswer;
        @Bind(R.id.lv_answer)
        LinearLayout mLvAnswer;
        @Bind(R.id.title)
        TextView mTitle;
        @Bind(R.id.content)
        TextView mContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
